<?

//Data loading
$title='MEMORIAL ADJUSTMENT VOUCHER';
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = 'PT. MASAJI PRAYASA CARGO';

$page   = 'PAGE';

$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = GridList ();
$pdf->GridTable($Result);
$pdf->Output();


function GridList () {
		    $DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
                    $SQL = "SELECT * FROM ais_memorial WHERE nobkt='".GetParam("nobkt","")."' ORDER BY urut";
                    return $DBConnection->dbc->get_results($SQL,ARRAY_A);
} 

function ReadHeader($nobkt) {
  global $DBConnection;
  $SQL = "SELECT *,DATE_FORMAT(tglbkt,'%d %M, %Y') as spell_date  FROM ais_memorial WHERE nobkt='$nobkt' AND urut=999";
  return $DBConnection->dbc->get_row($SQL);
}

class PDFReport extends PDF {

	function Header() {
		global $title,$perush,$page,$DEFINE_FONT;
		if ($DEFINE_FONT==0) {
			$this->AddFont('Arial','','arialn.php');
			$DEFINE_FONT=1;
		}
		$Field = ReadHeader(GetParam("nobkt",""));
                $this->spell_date = strtoupper($Field->spell_date);
                list($this->year,$this->month,$this->day) = explode("-",$Field->tglbkt);
                
		$this->SetFont('Arial','',10);
                $this->Cell(50,5,$perush,0,1,'C',0);
                $this->SetFont('Arial','',16);
                if (GetParam("curr","")) $this->Cell(200,5,$title." (".GetParam("curr","").")",0,1,'C',0);
                else $this->Cell(200,5,$title,0,1,'C',0);
		$this->SetFont('Arial','',10);
				
                $this->Cell(170,5,"NO: ",0,0,'R',0);$this->Cell(30,5,GetParam("nobkt",""),0,1,'L',0);
                $this->Cell(170,5,"TANGGAL: ",0,0,'R',0);$this->Cell(30,5,$this->day."/".$this->month."/".$this->year,0,1,'L',0);
                $this->Cell(170,5,"CURRENCY: ",0,0,'R',0);$this->Cell(30,5,$Field->curr,0,1,'L',0);
                $this->SetLeftMargin(5);
		$this->Ln();
				
                $this->Cell(200,5,$page." ".$this->PageNo(),0,1,'R',0);
                $this->SetLeftMargin(5);
                //$this->Line(5,30,210,30);
                //$this->Ln();
                $this->Ln();

	    //Header
	    //Column widths
        $w=array(10,20,20,20,85,25,25);
        $this->SetFont('Arial','',8);
        $this->Cell($w[0],7,"NO.",1,0,'C',0);        
        $this->Cell($w[1],7,"DEBTUR",1,0,'C',0);
        $this->Cell($w[2],7,"ACC. ACTIVITY",1,0,'C',0);
	$this->Cell($w[3],7,"SKADA",1,0,'C',0);	    
	$this->Cell($w[4],7,"URAIAN",1,0,'C',0);
	$this->Cell($w[5],7,"DEBET",1,0,'C',0);
	$this->Cell($w[6],7,"CREDIT",1,0,'C',0);
        $this->Ln(); 
	}

	function GridTable($MyResult) {
	    //Column widths
	    $w=array(10,20,20,20,85,25,25);
	    //Data
        if ($MyResult)
	    foreach($MyResult as $row)
	    {
		if ($row["dk"]=='D') $row["jumlah1"] = $row["jumlah"];
		else $row["jumlah2"] = $row["jumlah"];
		$totaldebet = $totaldebet + $row["jumlah1"];
		$totalcredit = $totalcredit + $row["jumlah2"];
                $n++;
	        $this->Cell($w[0],7,$row["urut"].".",'LR',0,'R');
	        $this->Cell($w[1],7,$row["debtur"],'LR',0,'C');
		$this->Cell($w[2],7,$row["kdact"],'LR');
	        $this->Cell($w[3],7,$row["skada"],'LR');
                $this->Cell($w[4],7,$row["uraian"],'LR');
	        $this->Cell($w[5],7,FormatNumber($row["jumlah1"],2),'LR',0,'R');
		$this->Cell($w[6],7,FormatNumber($row["jumlah2"],2),'LR',0,'R');
	        $this->Ln();
	    }
	        $this->Cell($w[0]+$w[1]+$w[2]+$w[3]+$w[4],7,"JUMLAH:",1,0,'R',0);
	        $this->Cell($w[5],7,FormatNumber($totaldebet,2),1,0,'R',0);
		$this->Cell($w[6],7,FormatNumber($totalcredit,2),1,0,'R',0);
	        $this->Ln();
                $this->Ln();
                $this->Cell($w[0]+$w[1]+$w[2]+$w[3],7,"",0,'R',0);
                $this->Cell($w[4]+$w[5],7,GetOfficeLocation().", ".$this->spell_date,0,'C',0);
	        $this->Ln();
                $this->Ln();
                
	    
	    //Closure line
	}

	function Footer() {
	    //Closure line
	    //$this->Cell(205,0,'','T');
	}

}


?>
